public class Day8 {
    public static void main(String[] args) {

    }
    public int getMaxLen(int[] nums) {
        int n = nums.length;
        int[] f = new int[n];
        int[] g = new int[n];
        if(nums[0] > 0) f[0]=1;
        else f[0]=0;
        if(nums[0]>=0) g[0]=0;
        else g[0]=1;
        int ret = f[0];
        for(int i=1;i<n;i++) {
            if(nums[i] > 0) {
                f[i]=1+f[i-1];
                g[i]=g[i-1]==0?0:1+g[i-1];
            }else if(nums[i]<0) {
                f[i]=g[i-1]==0?0:1+g[i-1];
                g[i]=1+f[i-1];
            }else {
                f[i]=g[i]=0;
            }
            ret = Math.max(ret,f[i]);
        }
        return ret;
    }


    public static int numberOfArithmeticSlices(int[] nums) {
        int n = nums.length;
        if(n < 3) return 0;
        int[][] dp = new int[n][2];
        dp[0][0]=dp[0][1]=dp[1][1];
        dp[1][0]=nums[1]-nums[0];
        int ret = 0;
        for(int i=2;i<n;i++) {
            dp[i][0]=nums[i]-nums[i-1];
            if(dp[i][0] == dp[i-1][1]) {
                dp[i][1]=1;
                if(dp[i-1][1]>0) {
                    dp[i][1]+=dp[i-1][1];
                }
            }
            ret+=dp[i][1];
        }
        return ret;
    }
}
